function quick(arr) {
  if (arr.length <= 1) {
    return arr;
  }
  let left = [],
    right = [],
    k = arr.splice(0, 1)[0];
  for (var i = 0; i < arr.length; i++) {
    if (arr[i] > k) {
      right.push(arr[i]);
    } else {
      left.push(arr[i]);
    }
  }
  return quick(left).concat([k], quick(right));
}
let result = quick([1, 9, 8, 5, 6, 10, 3, 4, 7]);
console.log(result);
